<?php

namespace Common\Controller;

use Think\Controller;

class CommonController extends Controller
{
    public function _initialize()
    {
        $userInfo = session('userInfo');
        if (empty($userInfo)) {
            $this->accessOut();
            return;
        }
        $userInfo = tbs_new_decode($userInfo);
        $userInfo = json_decode($userInfo, true);
        C('userInfo', $userInfo);
        $this->getAllowNodes();
    }

    public function show_404()
    {
        $this->display('404');
    }

    public function show_error()
    {
        $this->display('error');
    }

    public function ajaxCallMsg($error_code = 0, $msg = '', $data = array())
    {
        $returnData = array(
            'error_code' => $error_code,
            'msg' => $msg
        );

        if ($data) {
            $returnData['data'] = $data;
        }

        $this->ajaxReturn($returnData);
    }

    public function accessOut()
    {
        redirect('/home/login/index');
    }

    protected function clearUserData()
    {
        session('userInfo', NULL);
    }

    public function access_deny()
    {
        $this->show('<center>对不起,您没有访问权限!</center>', 'utf-8');
        exit();
    }
    
    public function getAllowNodes(){
        $userInfo =  C('userInfo');
//        echo C('USER_AUTH_TYPE');
        //保存权限到session

//        用户对应多个角色
//        角色对应多个节点
         \Org\Util\Rbac::saveAccessList($userInfo['id']);
//         var_dump($_SESSION['_ACCESS_LIST']);die;

//        //判断权限
//        $result = \Org\Util\Rbac::AccessDecision();
//        echo $result ? 'yes' : 'no' ;

        //该模块所有权限
//        $module_auth = \Org\Util\Rbac::getModuleAccessList($userInfo['id'],MODULE_NAME);
//        var_dump($module_auth);die;
        //该模块所有权限
//        $module_auth = \Org\Util\Rbac::getModuleAccessList($userInfo['id']);
//        var_dump($module_auth);die;



    }
    


}